package com.ssy.lingxi.order.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.constant.DeliveryHistoryTypeEnum;
import com.ssy.lingxi.order.model.constant.DeliveryOrderTypeStatusEnum;
import com.ssy.lingxi.order.model.vo.basic.request.*;
import com.ssy.lingxi.order.model.vo.basic.response.*;
import com.ssy.lingxi.order.service.web.IDeliveryPlanService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 订单能力 - 送货通知单
 * @author czh
 * @version 2.0.0
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/order/deliveryNoticeOrder")
public class DeliveryNoticeOrderController {

    @Resource
    private IDeliveryPlanService planService;

    /**
     * “送货通知单” - 送货通知单协同 - 分页查询
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/buyer/page", method = RequestMethod.GET)
    public Wrapper<PageData<NoticeOrderQueryVO>> pageByBuyer(@RequestHeader HttpHeaders headers, @Valid NoticeOrderPageVO request) {
        return planService.pageBuyerNoticeOrder(headers, request);
    }

    /**
     * “送货通知单” - 分页查询
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/vendor/page", method = RequestMethod.GET)
    public Wrapper<PageData<NoticeOrderQueryVO>> pageByVendor(@RequestHeader HttpHeaders headers, @Valid NoticeOrderPageVO request) {
        return planService.pageVendorNoticeOrder(headers, request);
    }

    /**
     * “送货通知单” - 新增送货通知单（SRM）
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/srm/create", method = RequestMethod.POST)
    public Wrapper<Void> createBySRM(@RequestHeader HttpHeaders headers, @RequestBody @Valid NoticeOrderParamVO request) {
        return planService.createNoticeOrder(headers, request, DeliveryOrderTypeStatusEnum.SRM.getCode());
    }


    /**
     * “送货通知单” - 新增送货通知单（B2B）
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/b2b/create", method = RequestMethod.POST)
    public Wrapper<Void> createByB2B(@RequestHeader HttpHeaders headers, @RequestBody @Valid NoticeOrderParamVO request) {
        return planService.createNoticeOrder(headers, request, DeliveryOrderTypeStatusEnum.B2B.getCode());
    }

    /**
     * “送货通知单” - 详情
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Wrapper<NoticeOrderDetailVO> detail(@RequestHeader HttpHeaders headers, @Valid IdVO request) {
        return planService.getNoticeOrderDetail(headers, request);
    }

    /**
     * “送货通知单” - 详情 - 流转记录
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/deliveryHistory", method = RequestMethod.GET)
    public Wrapper<List<DeliveryOuterHistoryVO>> deliveryHistory(@RequestHeader HttpHeaders headers, @Valid IdVO request) {
        return planService.deliveryHistory(headers, request, DeliveryHistoryTypeEnum.NOTICE_ORDER.getCode());
    }

    /**
     * “送货通知单” - 详情 - 物料分页列表
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail/page", method = RequestMethod.GET)
    public Wrapper<PageData<NoticeOrderProductQueryVO>> pageProducts(@RequestHeader HttpHeaders headers, @Valid NoticeOrderIdPageVO request) {
        return planService.pageNoticeOrderProducts(headers, request);
    }

    /**
     * 送货通知单 - 修改通知单
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<Void> update(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryNoticeOrderUpdateVO request) {
        return planService.updateNoticeOrder(headers, request);
    }

    /**
     * 送货通知单 - 作废通知单
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/invalid", method = RequestMethod.POST)
    public Wrapper<Void> invalid(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryInvalidVO request) {
        return planService.invalidNoticeOrder(headers, request);
    }

    /**
     * “送货通知单” - 确认送货通知单
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return
     */
    @RequestMapping(value = "/confirm", method = RequestMethod.POST)
    public Wrapper<Void> confirm(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryVerifyVO request) {
        return planService.confirmNoticeOrder(headers, request);
    }

    /**
     * 送貨通知單-生成送货单所需数据
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/create/deliveryOrder", method = RequestMethod.GET)
    public Wrapper<DeliveryOrderCreateByPlanVO> DeliveryOrderByNoticeCreate(@RequestHeader HttpHeaders headers, @Valid IdVO request) {
        return planService.DeliveryOrderByNoticeCreate(headers, request);
    }

}
